<?php

namespace app\user\logic;

use app\model\Barn;
use app\model\Fence;
use app\model\Pig;

class IndexLogic
{
    /**
     * @Description 首页 栋栏猪统计
     * @author: zj
     * @param $param
     * @time 2024/03/20 17:11:12
     * @return array
     * @throws \think\db\exception\DbException
     */
    public function statistic($param)
    {
        $factoryId = request()->user_info['factory_id'];

        $barnModel = new Barn();
        $barnCount = $barnModel->checkBarnCount($factoryId);

        $fenceModel = new Fence();
        $fenceCount = $fenceModel->checkFenceCount($factoryId,$param['barn_id']);

        $pigModel = new Pig();
        $pigCount = $pigModel->checkPigCount($factoryId,$param['barn_id']);

        if ($param['barn_id']) {
            return [
                'fence_count' => $fenceCount,
                'pig_count' => $pigCount,
            ];
        }

        return [
            'barn_count' => $barnCount,
            'fence_count' => $fenceCount,
            'pig_count' => $pigCount,
        ];
    }
}